#pragma once

#include "node.h"
#include <memory>

class Point
{
public:
    explicit Point( int a, int b ) noexcept;
    virtual ~Point();

    Point operator+( const Point & p ) const;
    Point operator-( const Point & p ) const;

    int x;
    int y;
};

class Edge final
{
public:
    enum Position : int
    {
        LEFT,
        RIGHT,
        BELONG,
        BACK,
        FRONT
    };
    explicit Edge( Point a, Point b ) noexcept;
    ~Edge();

    Position relPos( const Point & p ) const;
    bool isCrossing( const Edge & e ) const;

    static double polarAngle( const Edge & e );
    static double polarAngle( const Point & from, const Point & to );

    const Point from;
    const Point to;
};

class Vertex final : public Point, public Node
{
public:
    explicit Vertex( int a, int b ) noexcept;
    explicit Vertex( const Point & p ) noexcept;
    virtual ~Vertex();

    enum Rotation : int
    {
        CLOCKWISE,
        COUNTERCLOCKWISE
    };

    Vertex * cw();
    Vertex * cww();
};

class Figure
{
public:
    explicit Figure( std::unique_ptr<Vertex> );
    ~Figure();

    bool isCrossing( const Edge & e ) const;
    bool isPointIn( const Point & p ) const;
    size_t size;

private:
    std::unique_ptr<Vertex> vertexes;
    void resize();
};
